﻿using FoundationLib.Ifc.Data;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nh = NHibernate;

namespace FoundationLib.Data.NHibernate
{
	/// <summary>
	/// A proxy for an underlying NHibernate transaction.
	/// </summary>
	public class NHibernateTransactionProxy : ITransaction
	{
		/// <summary>
		/// The underlying NHibernate transaction
		/// </summary>
		private Nh.ITransaction transaction;

		/// <summary>
		/// Creates a new NHibernate transaction proxy.
		/// </summary>
		/// <param name="tran">The underlying NHibernate Transaction</param>
		public NHibernateTransactionProxy(Nh.ITransaction tran)
		{
			Contract.Requires(tran != null);
			this.transaction = tran;
		}

		/// <see cref="ITransaction.Commit()"/>
		public void Commit()
		{
			this.transaction.Commit();
		}

		/// <see cref="ITransaction.Rollback()"/>
		public void Rollback()
		{
			this.transaction.Rollback();
		}
	}
}
